/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ebm;

import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;

/**
 *
 * @author vincenzoscognamiglio
 */
public class scanDir {

    public static ArrayList<String> getFirstLevelDirectory(String path) {
        ArrayList<String> vettDir = new ArrayList<String>();
        File dirToScan = new File(path);
        if (dirToScan.isDirectory()) {
            for (int cn = 0; cn < dirToScan.listFiles().length; cn++) {
                if ((dirToScan.listFiles()[cn]).isDirectory()) {
                    vettDir.add(dirToScan.list()[cn]);
                    System.out.println("Aggiunto:" + dirToScan.list()[cn]);
                }
            }
        }
        return vettDir;
    }
    
    
    public static ArrayList<String> getFirstLevelFile(String path) {
      ArrayList<String> vettDir = new ArrayList<String>();        File dirToScan = new File(path);
        FilenameFilter ff = new FilenameFilter() {
        public boolean accept(File directory, String fileName) {
            boolean ok = false;
            String myFileName = fileName.toLowerCase();
            if ((myFileName.endsWith(".txt")) || (myFileName.endsWith(".doc")) || (myFileName.endsWith(".epub")) || (myFileName.endsWith(".pdf")) || (myFileName.endsWith(".rtf")) || (myFileName.endsWith(".mobi")) || (myFileName.endsWith(".chm") || (myFileName.endsWith(".lit"))|| (myFileName.endsWith(".rpc")))|| (myFileName.endsWith(".opf")))
                ok = true;
            return ok;
        }
        };
        if (dirToScan.isDirectory()) {
            File[] listaFile = dirToScan.listFiles(ff);
            String[] listaNomiFile = dirToScan.list(ff);
            if (listaNomiFile != null)
            for (int cn = 0; cn < listaFile.length; cn++) {
                if (!(listaFile[cn]).isDirectory()) {
                    vettDir.add(listaNomiFile[cn]);
                    System.out.println("Aggiunto:" + listaNomiFile[cn]);
                }
            }
        }
        return vettDir;
    }
}
